﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data.SqlClient;

public class tbCriteriaDB
{
    #region[tbCriteria_Add]
    public static bool tbCriteria_Add(tbCriteriaDATA _tbCriteriaDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbCriteria_Add", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@psID", _tbCriteriaDATA.psID));
                dbCmd.Parameters.Add(new SqlParameter("@criName", _tbCriteriaDATA.criName));
                dbCmd.Parameters.Add(new SqlParameter("@criNotes", _tbCriteriaDATA.criNotes));
                dbCmd.Parameters.Add(new SqlParameter("@criOrd", _tbCriteriaDATA.criOrd));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbCriteria_Update]
    public static bool tbCriteria_Update(tbCriteriaDATA _tbCriteriaDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbCriteria_Update", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@criId", _tbCriteriaDATA.criId));
                dbCmd.Parameters.Add(new SqlParameter("@psID", _tbCriteriaDATA.psID));
                dbCmd.Parameters.Add(new SqlParameter("@criName", _tbCriteriaDATA.criName));
                dbCmd.Parameters.Add(new SqlParameter("@criNotes", _tbCriteriaDATA.criNotes));
                dbCmd.Parameters.Add(new SqlParameter("@criOrd", _tbCriteriaDATA.criOrd));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbCriteria_Delete]
    public static bool tbCriteria_Delete(string criId)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbCriteria_Delete", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@criId", criId));
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbCriteria_GetByAll]
    public static List<tbCriteriaDATA> tbCriteria_GetByAll()
    {
        List<tbCriteriaDATA> list = new List<tbCriteriaDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbCriteria_GetByAll", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbCriteriaDATA objtbCriteriaDATA = new tbCriteriaDATA(
                        reader["criId"].ToString(),
                        reader["psID"].ToString(),
                        reader["criName"].ToString(),
                        reader["criNotes"].ToString(),
                        reader["criOrd"].ToString(),
                        reader["psName"].ToString());
                        list.Add(objtbCriteriaDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
    #region[tbCriteria_GetByID]
    public static List<tbCriteriaDATA> tbCriteria_GetByID(string criId)
    {
        List<tbCriteriaDATA> list = new List<tbCriteriaDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbCriteria_GetByID", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@criId", criId));
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbCriteriaDATA objtbCriteriaDATA = new tbCriteriaDATA(
                        reader["criId"].ToString(),
                        reader["psID"].ToString(),
                        reader["criName"].ToString(),
                        reader["criNotes"].ToString(),
                        reader["criOrd"].ToString(),
                        reader["psName"].ToString());
                        list.Add(objtbCriteriaDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
    #region[tbCriteria_GetBypsID]
    public static List<tbCriteriaDATA> tbCriteria_GetBypsID(string psID)
    {
        List<tbCriteriaDATA> list = new List<tbCriteriaDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbCriteria_GetBypsID", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@psID", psID));
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbCriteriaDATA objtbCriteriaDATA = new tbCriteriaDATA(
                        reader["criId"].ToString(),
                        reader["psID"].ToString(),
                        reader["criName"].ToString(),
                        reader["criNotes"].ToString(),
                        reader["criOrd"].ToString(),
                        reader["psName"].ToString());
                        list.Add(objtbCriteriaDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
    #region[tbCriteria_GetByuID]
    public static List<tbCriteriaDATA> tbCriteria_GetByuID(string uID)
    {
        List<tbCriteriaDATA> list = new List<tbCriteriaDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbCriteria_GetByuID", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@uID", uID));
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbCriteriaDATA objtbCriteriaDATA = new tbCriteriaDATA(
                        reader["criId"].ToString(),
                        reader["psID"].ToString(),
                        reader["criName"].ToString(),
                        reader["criNotes"].ToString(),
                        reader["criOrd"].ToString());
                        list.Add(objtbCriteriaDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
}
